using FreeSwitch.EventSocket.Events;

namespace FreeSwitch.EventSocket.Events.Channel
{
    public class ChannelBase : Event
    {
    	public ChannelBase()
    	{
    		UniqueId = string.Empty;
    	}

    	public override bool IsChannelEvent
        {
            get { return true; }
        }

    	/// <summary>
    	/// Information about the used channel and it's state.
    	/// </summary>
    	public ChannelInfo ChannelInfo { get; set; }

    	public string UniqueId { get; set; }

    	public string AnswerState { get; set; }

    	public string CallDirection { get; set; }

    	public override bool ParseCommand(string name, string value)
        {
			if (name == "unique-id")
				UniqueId = value;
			else if (name == "answer-state")
				AnswerState = value;
			else if (name == "call-direction")
				CallDirection = value;
			else if (name.Length > 8 && name.Substring(0, 8) == "channel-")
			{
				if (ChannelInfo == null)
					ChannelInfo = new ChannelInfo();
				return ChannelInfo.Parse(name, value);
			}
			else
				return base.ParseCommand(name, value);

            return true;
        }

        public override string ToString()
        {
            return
                "ChannelBase(" + UniqueId + " [" + CallDirection + "] " + AnswerState +
                ", channelInfo{" + ChannelInfo + "})";
        }
    }
}
